package cn.iocoder.yudao.module.ems.dal.mysql.classification;

import java.util.*;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.ems.dal.dataobject.classification.ClassificationDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.ems.controller.admin.classification.vo.*;
import org.apache.ibatis.annotations.Select;

/**
 * 分类 Mapper
 *
 * @author dason
 */
@Mapper
public interface ClassificationMapper extends BaseMapperX<ClassificationDO> {

    default PageResult<ClassificationDO> selectPage(ClassificationPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ClassificationDO>()
                .likeIfPresent(ClassificationDO::getName, reqVO.getName())
                .eqIfPresent(ClassificationDO::getLeaderUserId, reqVO.getLeaderUserId())
                .eqIfPresent(ClassificationDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(ClassificationDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .orderByDesc(ClassificationDO::getId));
    }

//    default List<ClassificationDO> selectList(ClassificationExportReqVO reqVO) {
//        return selectList(new LambdaQueryWrapperX<ClassificationDO>()
//                .likeIfPresent(ClassificationDO::getName, reqVO.getName())
//                .eqIfPresent(ClassificationDO::getLeaderUserId, reqVO.getLeaderUserId())
//                .eqIfPresent(ClassificationDO::getStatus, reqVO.getStatus())
//                .betweenIfPresent(ClassificationDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
//                .orderByDesc(ClassificationDO::getId));
//    }

    default List<ClassificationDO> selectList(ClassificationListReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<ClassificationDO>()
                .likeIfPresent(ClassificationDO::getName, reqVO.getName())
                .eqIfPresent(ClassificationDO::getStatus, reqVO.getStatus()));
    }

    @Select("SELECT COUNT(*) FROM ems_spare_classification WHERE update_time > #{maxUpdateTime}")
    Long selectCountByUpdateTimeGt(Date maxUpdateTime);

}
